home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / SEARCH / RUBICON / TAREDIT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-21  |  8KB  |  326 lines

  1. {*********************************************************}
  2. {*             TAREDIT.PAS 1.20             *}
  3. {*      Copyright (c) Tamarack Associates 1996.     *}
  4. {*           All rights reserved.          *}
  5. {*********************************************************}
  6.  
  7. {$B-}     {* Boolean evaluation *}
  8. {$G+}     {* Generate 286 code  *}
  9. {$X+}     {* eXtended syntax    *}
  10.  
  11. UNIT taREdit;
  12.  
  13. INTERFACE
  14.  
  15. USES
  16.   {$IFDEF WIN32}
  17.   Windows,
  18.   {$ELSE}
  19.   WinTypes,
  20.   {$ENDIF}
  21.   Messages, SysUtils, Classes, Consts, Graphics, Controls, Forms, Dialogs,
  22.   DsgnIntf, TypInfo, StrEdit, StdCtrls, taRubicn, DB, DBTables, Buttons;
  23.  
  24. TYPE
  25.  
  26.   TFieldsForm = class(TForm)
  27.     AvailListBox: TListBox;
  28.     SelectListBox: TListBox;
  29.     AddBtn: TButton;
  30.     RemoveBtn: TButton;
  31.     AvailLabel: TLabel;
  32.     SelectLabel: TLabel;
  33.     OkBtn: TBitBtn;
  34.     CancelBtn: TBitBtn;
  35.     procedure CancelBtnClick(Sender: TObject);
  36.     procedure AddBtnClick(Sender: TObject);
  37.     procedure RemoveBtnClick(Sender: TObject);
  38.     procedure AvailListBoxDblClick(Sender: TObject);
  39.     procedure SelectListBoxDblClick(Sender: TObject);
  40.   PRIVATE
  41.     { Private declarations }
  42.     FDictionary : TAbstractDictionary;
  43.     FModified    : BOOLEAN;
  44.     PROCEDURE FieldNamesSetup;
  45.     PROCEDURE SubFieldNamesSetup;
  46.   PUBLIC
  47.     { Public declarations }
  48.   END;
  49.  
  50.   TEditFunc = FUNCTION(Dictionary : TAbstractDictionary ;
  51.                List : TStrings) : BOOLEAN;
  52.  
  53.   TFieldNamesProperty = CLASS(TStringListProperty)
  54.    FUNCTION GetAttributes : TPropertyAttributes ; OVERRIDE;
  55.    FUNCTION GetValue : STRING ; OVERRIDE;
  56.    PROCEDURE Edit ; OVERRIDE;
  57.    PROCEDURE EditPrim(EditFunc : TEditFunc);
  58.   END;
  59.  
  60.   TSubFieldNamesProperty = CLASS(TFieldNamesProperty)
  61.    PROCEDURE Edit ; OVERRIDE;
  62.   END;
  63.  
  64.   TtaIndexFieldNameProperty = CLASS(TStringProperty)
  65.   PUBLIC
  66.    FUNCTION  GetAttributes : TPropertyAttributes ; OVERRIDE;
  67.    PROCEDURE GetValues(Proc : TGetStrProc) ; OVERRIDE;
  68.   END;
  69.  
  70.   TtaWildCardProperty = CLASS(TCharProperty)
  71.   PUBLIC
  72.    FUNCTION  GetAttributes : TPropertyAttributes ; OVERRIDE;
  73.    FUNCTION  GetValue : STRING ; OVERRIDE;
  74.    PROCEDURE GetValues(Proc : TGetStrProc) ; OVERRIDE;
  75.    PROCEDURE SetValue(CONST Value : STRING); OVERRIDE;
  76.   END;
  77.  
  78.   TtaWordDelimsProperty = CLASS(TStringProperty)
  79.   PUBLIC
  80.    FUNCTION  GetValue : STRING ; OVERRIDE;
  81.   END;
  82.  
  83. IMPLEMENTATION
  84.  
  85. {$R *.DFM}
  86.  
  87. FUNCTION EditFieldNames(Dictionary : TAbstractDictionary ;
  88.             List : TStrings) : BOOLEAN ; FAR;
  89. BEGIN
  90.  WITH TFieldsForm.Create(Application) DO
  91.   TRY
  92.    FDictionary := Dictionary;
  93.    FieldNamesSetup;
  94.    ShowModal;
  95.    IF FModified THEN
  96.     BEGIN
  97.      List.Clear;
  98.      List.Assign(SelectListBox.Items);
  99.      IF Dictionary IS TSearchDictionary THEN
  100.       TSearchDictionary(Dictionary).SubFieldNames.Clear
  101.     END;
  102.    Result := FModified;
  103.   FINALLY
  104.    Free
  105.   END
  106. END;
  107.  
  108. FUNCTION EditSubFieldNames(Dictionary : TAbstractDictionary ;
  109.             List : TStrings) : BOOLEAN ; FAR;
  110. BEGIN
  111.  WITH TFieldsForm.Create(Application) DO
  112.   TRY
  113.    Caption := 'SubFieldNames Property Editor';
  114.    SelectLabel.Caption := 'SubFieldNames';
  115.    FDictionary := Dictionary;
  116.    SubFieldNamesSetup;
  117.    ShowModal;
  118.    IF FModified THEN
  119.     BEGIN
  120.      List.Clear;
  121.      List.Assign(SelectListBox.Items)
  122.     END;
  123.    Result := FModified
  124.   FINALLY
  125.    Free
  126.   END
  127. END;
  128.  
  129. PROCEDURE   TFieldsForm.FieldNamesSetup;
  130. VAR        i : INTEGER;
  131. BEGIN
  132.  WITH FDictionary, DataSource.DataSet DO
  133.   FOR i := 0 TO FieldCount - 1 DO
  134.    WITH Fields[i] DO
  135.     IF DataType IN FieldTypes THEN
  136.      IF (FieldNames.Count = 0) OR
  137.     (FieldNames.IndexOf(FieldName) = -1) THEN
  138.       AvailListBox.Items.Add(FieldName)
  139.      ELSE
  140.       SelectListBox.Items.Add(FieldName)
  141. END;
  142.  
  143. PROCEDURE   TFieldsForm.SubFieldNamesSetup;
  144. VAR        i : INTEGER;
  145. BEGIN
  146.  WITH FDictionary AS TSearchDictionary, DataSource.DataSet DO
  147.   FOR i := 0 TO FieldCount - 1 DO
  148.    WITH Fields[i] DO
  149.     IF (DataType IN FieldTypes) AND
  150.        ((FieldNames.Count = 0) OR
  151.     (FieldNames.IndexOf(FieldName) <> -1)) THEN
  152.      IF (SubFieldNames.Count = 0) OR
  153.     (SubFieldNames.IndexOf(FieldName) = -1) THEN
  154.       AvailListBox.Items.Add(FieldName)
  155.      ELSE
  156.       SelectListBox.Items.Add(FieldName)
  157. END;
  158.  
  159. FUNCTION   TFieldNamesProperty.GetAttributes : TPropertyAttributes;
  160. BEGIN
  161.  Result :=[paDialog]
  162. END;
  163.  
  164. FUNCTION   TFieldNamesProperty.GetValue : STRING;
  165. BEGIN
  166.  Result := Format('(%s)',[GetPropType^.Name])
  167. END;
  168.  
  169. PROCEDURE  TFieldNamesProperty.Edit;
  170. VAR       D : TAbstractDictionary;
  171.        B : TBuildDictionary;
  172. BEGIN
  173.  D := TAbstractDictionary(GetComponent(0));
  174.  B := NIL;
  175.  IF D IS TUpdateDictionary THEN B := TUpdateDictionary(D).Builder;
  176.  IF D IS TSearchDictionary THEN B := TSearchDictionary(D).Builder;
  177.  IF B = NIL THEN EditPrim(EditFieldNames)
  178. END;
  179.  
  180. PROCEDURE  TFieldNamesProperty.EditPrim(EditFunc : TEditFunc);
  181. VAR       D : TAbstractDictionary;
  182.        ErrMsg : STRING[30];
  183. BEGIN
  184.  D := TAbstractDictionary(GetComponent(0));
  185.  ErrMsg := '';
  186.  IF D.DataSource = NIL THEN ErrMsg := 'DataSource is nil'
  187.  ELSE
  188.   IF D.DataSource.DataSet = NIL THEN ErrMsg := 'DataSet is nil'
  189.   ELSE
  190.    IF NOT D.DataSource.DataSet.Active THEN ErrMsg := 'DataSet is Inactive';
  191.  IF ErrMsg ='' THEN
  192.   IF EditFunc(TAbstractDictionary(GetComponent(0)),TStrings(GetOrdValue)) THEN
  193.    Modified
  194.   ELSE
  195.  ELSE
  196.   IF MessageDlg(ErrMsg + '.  Do you wish to use the string list editor?',
  197.         mtConfirmation, mbOkCancel,0) = mrOk THEN
  198.    INHERITED Edit
  199. END;
  200.  
  201. PROCEDURE  TSubFieldNamesProperty.Edit;
  202. BEGIN
  203.  EditPrim(EditSubFieldNames)
  204. END;
  205.  
  206. procedure TFieldsForm.CancelBtnClick(Sender: TObject);
  207. begin
  208.  FModified := FALSE
  209. end;
  210.  
  211. procedure TFieldsForm.AddBtnClick(Sender: TObject);
  212. VAR      i : INTEGER;
  213. begin
  214.  WITH AvailListBox DO
  215.   BEGIN
  216.    i := ItemIndex;
  217.    IF i >= 0 THEN
  218.     BEGIN
  219.      SelectListBox.Items.Add(Items[i]);
  220.      Items.Delete(i);
  221.      FModified := TRUE
  222.     END
  223.   END
  224. end;
  225.  
  226. procedure TFieldsForm.RemoveBtnClick(Sender: TObject);
  227. VAR      i : INTEGER;
  228. begin
  229.  WITH SelectListBox DO
  230.   BEGIN
  231.    i := ItemIndex;
  232.    IF i >= 0 THEN
  233.     BEGIN
  234.      AvailListBox.Items.Add(Items[i]);
  235.      Items.Delete(i);
  236.      FModified := TRUE
  237.     END
  238.   END
  239. end;
  240.  
  241. procedure TFieldsForm.AvailListBoxDblClick(Sender: TObject);
  242. begin
  243.  AddBtnClick(NIL)
  244. end;
  245.  
  246. procedure TFieldsForm.SelectListBoxDblClick(Sender: TObject);
  247. begin
  248.  RemoveBtnClick(NIL)
  249. end;
  250.  
  251. FUNCTION  TtaIndexFieldNameProperty.GetAttributes : TPropertyAttributes;
  252. BEGIN
  253.  Result := [paValueList] + INHERITED GetAttributes
  254. END;
  255.  
  256. PROCEDURE TtaIndexFieldNameProperty.GetValues(Proc : TGetStrProc);
  257. VAR      i : INTEGER;
  258. BEGIN
  259.  WITH GetComponent(0) AS TAbstractDictionary DO
  260.   IF (DataSource <> NIL) AND
  261.      (DataSource.DataSet <> NIL) AND
  262.      DataSource.DataSet.Active AND
  263.      (DataSource.DataSet IS TTable) THEN
  264.    WITH TTable(DataSource.DataSet) DO
  265.     FOR i := 0 TO IndexDefs.Count - 1 DO
  266.      WITH IndexDefs[i] DO
  267.       IF StrictChecking THEN
  268.        IF (POS(';',Fields) = 0) AND
  269.       (ixUnique IN Options) AND
  270.       (FindField(Fields) <> NIL) AND
  271.       (FindField(Fields).DataType IN [ftSmallInt,ftWord,ftInteger]) THEN
  272.     Proc(Fields)
  273.        ELSE
  274.       ELSE Proc(Fields)
  275. END;
  276.  
  277. FUNCTION  TtaWildCardProperty.GetAttributes : TPropertyAttributes;
  278. BEGIN
  279.  Result := [paValueList] + INHERITED GetAttributes
  280. END;
  281.  
  282. FUNCTION  TtaWildCardProperty.GetValue : STRING;
  283. BEGIN
  284.  Result := INHERITED GetValue;
  285.  IF Result = '#0' THEN
  286.   IF GetName = 'AnyChar' THEN Result := '*'
  287.   ELSE Result := '?'
  288. END;
  289.  
  290. PROCEDURE TtaWildCardProperty.GetValues(Proc : TGetStrProc);
  291. BEGIN
  292.  Proc('*');
  293.  Proc('?');
  294.  Proc('!');
  295.  Proc('@');
  296.  Proc('#');
  297.  Proc('$');
  298.  Proc('%');
  299.  Proc('&');
  300.  Proc('/');
  301.  Proc('\');
  302.  Proc('+');
  303.  Proc('|');
  304.  Proc('-');
  305. END;
  306.  
  307. PROCEDURE TtaWildCardProperty.SetValue(CONST Value : STRING);
  308. VAR      SD : TSearchDictionary;
  309.       Ch : CHAR;
  310. BEGIN
  311.  SD := GetComponent(0) AS TSearchDictionary;
  312.  Ch := Value[1];
  313.  IF ((GetName = 'AnyChar') AND (Ch = SD.OneChar)) OR
  314.     ((GetName = 'OneChar') AND (Ch = SD.AnyChar)) THEN
  315.   RAISE EPropertyError.Create(LoadStr(SInvalidPropertyValue))
  316.  ELSE INHERITED SetValue(Value)
  317. END;
  318.  
  319. FUNCTION  TtaWordDelimsProperty.GetValue : STRING;
  320. BEGIN
  321.  Result := INHERITED GetValue;
  322.  IF Result = '' THEN Result := DefaultWordDelims
  323. END;
  324.  
  325. END.
  326.